import msg from "../../../../utils/msg";
import { weeklyAbsent, weeklyAbsentExport } from "../../../../utils/request/api";
import User from "../../../../utils/user";
import { sr_data } from "../../s_worker/util";

// pages/user/weekly/weeklyDetail/weeklyDetail.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1 as number,
    data:[] as sr_data[],
    user:{} as User,
    week:1 as number,
    isAll:false,
    count:0 as number,
  },
  onClickLeft(){
    wx.navigateBack();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(option:any) {
    let week = option.week;
    let count=option.count;
    var user = new User;
    weeklyAbsent({openid:user.openid,week:week,page:1})
    .then((res:any)=>{
      this.setData({
        data:res.data.data,
        user:user,
        week:week,
        count:count,
      });
    });
  },
  download:async function(){
    await msg.confirm('是否导出数据','');
    let user = this.data.user;
    msg.Loading('导出数据中');
    await weeklyAbsentExport({data:{openid:user.openid,week:this.data.week},fileName:user.grade+"级第"+this.data.week+"周缺勤名单"});
    msg.hideLoading();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.count<=this.data.data.length) return;
    let user = this.data.user;
    msg.Loading('加载中')
    weeklyAbsent({openid:user.openid,week:this.data.week,page:(this.data.page+1)})
    .then((res:any)=>{
      let data = this.data.data;
      let arr3 =[...data, ...res.data.data];
      this.setData({
        data:arr3,
        page:this.data.page+1,
      });
      msg.hideLoading();
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})